package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * @ClassName CanvasDemo
 * @Description 画布
 * @Author wangss
 * @date 2020.07.04 18:15
 * @Version 1.0
 */
public class CanvasDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();

        Canvas canvas = new Canvas(500, 500);

        GraphicsContext graphicsContext = canvas.getGraphicsContext2D();

        graphicsContext.setFill(Color.RED);
        graphicsContext.fillRect(100, 100, 100, 100);

        graphicsContext.setStroke(Color.RED);
        graphicsContext.setLineWidth(4);
        graphicsContext.strokeRect(200, 200, 100, 100);

        graphicsContext.setStroke(Color.BLUE);
        graphicsContext.strokeLine(300, 100, 500, 100);

        an.getChildren().addAll(canvas);

        Scene scene = new Scene(an);
        primaryStage.setScene(scene);
        primaryStage.setHeight(1000d);
        primaryStage.setWidth(1500d);
        primaryStage.setAlwaysOnTop(true);
        primaryStage.show();
    }
}
